<template>
  <basic-container>
    <avue-crud
      :option="option"
      :data="data"
      :page.sync="page"
      :search.sync="search"
      :permission="permissionList"
      :table-loading="loading"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
      @selection-change="selectionChange"
    >
      <template slot-scope="{ row }" slot="menu">
        <el-button type="text" size="small" icon="el-icon-view" @click="openDialog(row)">详情</el-button>
      </template>
      <template slot="menuLeft">
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导出</el-button>
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
    </avue-crud>
    <el-dialog ref="dialog" title="详情" append-to-body :visible.sync="showDialog" :close-on-click-modal="false">
      <p>出库单号：{{ outboundOrderNo }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
      <avue-crud :option="detailOption" :data="detailData"></avue-crud>
      <span slot="footer" class="dialog-footer" :style="{ display: isNone }">
        <el-button size="small" icon="el-icon-circle-close" @click="showDialog = false">取 消</el-button>
      </span>
    </el-dialog>
    <export-comp ref="exportComp" page-api-url="mes-warehouse/outbound-return-record/page-query" :option="option" :page="page" :query="query" file-name="出库记录">
    </export-comp>
  </basic-container>
</template>

<script>
import { getList, getDetail } from '@/api/warehouse/shipment-record-query';
import { mapGetters } from 'vuex';
import exportComp from '@/components/export-comp';
import userConfig from '@/mixins/userConfig';
import userTableConfig from '@/components/user-table-config/index.vue';

export default {
  name: 'WarehouseShipmentRecordQuery',
  components: {
    exportComp,
    userTableConfig
  },
  mixins: [userConfig()],
  data() {
    return {
      query: {},
      search: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      params: {},
      selectionList: [],
      data: [],
      option: {
        height: 'calc(100vh - 406px)',
        columnBtn: false,
        calcHeight: 30,
        tip: false,
        refreshBtn: true, //刷新按钮是否显示
        searchBtn: true, // 显示查询的按钮
        border: true,
        index: true,
        dialogClickModal: false,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        viewBtn: false,
        selection: false,
        width: '100',
        menu: true,
        menuWidth: 100,
        searchLabelWidth: 100,
        searchMenuPosition: 'right',
        searchMenuSpan: 18,
        searchShow: true,
        indexLabel: '序号',
        column: [
          {
            label: '出库单号',
            prop: 'outboundOrderNo',
            search: true
          },
          {
            label: '单据类型',
            prop: 'outboundOrderType',
            search: true,
            type: 'select',
            dicData: [
              { label: '工单用料清单', value: 'BOMFWO' },
              { label: '生产领料单', value: 'PRF' },
              { label: '生产补料单', value: 'PSF' }
            ]
          },
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true
          },
          {
            label: '产品编码',
            prop: 'productPartNo',
            search: true
          },
          {
            label: '产品型号',
            prop: 'productModel'
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity'
          },
          {
            label: '操作人',
            prop: 'operationByName'
          },
          {
            label: '出库时间',
            prop: 'operationTime',
            search: true,
            searchOrder: 1,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间'
          },
          {
            label: '备注',
            prop: 'remark'
          }
        ]
      },
      showDialog: false,
      detailOption: {
        height: 400,
        columnBtn: false,
        calcHeight: 30,
        tip: false,
        refreshBtn: false, //刷新按钮是否显示
        searchBtn: false, // 显示查询的按钮
        border: true,
        index: true,
        addBtn: false,
        menu: false,
        indexLabel: '序号',
        column: [
          {
            label: '物料编码',
            prop: 'partNo'
          },
          {
            label: '物料型号',
            prop: 'partModel'
          },
          {
            label: '批次数量',
            prop: 'quantity'
          },
          {
            label: '内部批次',
            prop: 'lotNo'
          },
          {
            label: '品牌',
            prop: 'partBrand'
          }
        ]
      },
      detailData: [],
      outboundOrderNo: '',
      sheetNo: ''
    };
  },
  filters: {},
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {};
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.sheetPackingId);
      });
      return ids.join(',');
    }
  },
  methods: {
    searchReset() {
      this.query = {};
      this.search = {};
      this.page.currentPage = 1;
      this.page.pageSize = 20;
      this.onLoad(this.page, this.query);
    },
    searchChange(params, done) {
      if (params.operationTime) {
        params.startTime = params.operationTime[0];
        params.endTime = params.operationTime[1];
        delete params.operationTime;
      }
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, this.query);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.params);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },
    refreshChange() {
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.data = data.records;
        this.page.total = data.total;
        this.loading = false;
      });
    },
    openDialog(row) {
      this.showDialog = true;
      this.outboundOrderNo = row.outboundOrderNo;
      this.sheetNo = row.sheetNo;
      getDetail(row.id).then((res) => {
        this.detailData = this._get(res, 'data.data', []);
      });
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  watch: {}
};
</script>

<style lang="scss" scoped>
.el-dialog__wrapper {
  ::v-deep .avue-crud__menu {
    display: none;
  }
}
</style>
